import type { Profile } from '@/types/user';
import { removeToken, setLocalToken} from './../utils/auth';
import { getToken } from '@/utils/auth'
import { defineStore } from 'pinia'


export const useUserStore = defineStore('hm-user', () => {
  const token = ref(getToken() || '')
  //个人信息
  const profile = ref<Profile>({} as Profile)
  //修改个人信息
  const setProfile = (p: Profile) => { 
    profile.value = p
  }
  const setToken = (t:string) => { 
    token.value = t
    setLocalToken(t)
  }

  const clearUserInfo = () => { 
    token.value = ''
    removeToken()
  }

  return {
    token,
    setToken,
    clearUserInfo,
    profile,
    setProfile,
  }
})
